<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../vue.js"></script>
</head>

<body>
    <div class="app">
        <h1>{{title}}</h1>
        <hr>
        <parent></parent>
    </div>

    <template id="parent">
        <div>
            <h1>父元素的数据-{{name}}</h1>
            <hr>
            <childone @changeage="changeage"></childone>
            <hr>
            <childtwo ref="two"></childtwo>
        </div>
    </template>
    <template id="childone">
        <div>
            <h1>子元素的数据-{{name}}-{{age}}</h1>
            <button @click="changeage">点击修改儿子2号的age</button>
        </div>
    </template>

    <template id="childtwo">
        <div>
            <h1>子元素的数据-{{name}}-{{age}}</h1>
        </div>
    </template>
    <script>
        Vue.component("parent", {
            template: "#parent",
            data() {
                return {
                    name: "不吃鱼的猫",
                    age: 18
                }
            },
            methods: {
                changeage(n) {

                    this.$refs.two.age += n
                }
            }
        })

        Vue.component("childone", {
            template: "#childone",
            data() {
                return {
                    name: "我是儿子一号",
                    age: 5
                }
            },
            methods: {
                changeage() {
                    this.$emit("changeage", 5)
                }
            }
        })

        Vue.component("childtwo", {
            template: "#childtwo",
            data() {
                return {
                    name: "我是儿子二号",
                    age: 6
                }
            }
        })

        const vm = new Vue({
            data: {
                title: "兄弟改兄弟中间人自定义事件ref"
            }
        }).$mount(".app")
    </script>
</body>

</html>